package com.wolf.etl.service.impl;

import com.wolf.etl.model.EtlErrorLogModel;
import com.wolf.etl.service.IEtlErrorLogService;
import com.wolf.provider.order.enumerate.QUERY_TYPE;
import com.wolf.provider.order.info.PageBean;
import com.wolf.provider.order.info.PageInfo;
import com.wolf.provider.order.info.ParamBean;
import com.wolf.provider.order.service.impl.BaseServiceImpl;
import com.wolf.util.NumberUtil;
import com.wolf.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sdyang
 * @date 2019/10/14 16:41
 **/
@Service("etl_error_log")
public class EtlErrorLogServiceImpl extends BaseServiceImpl<Long> implements IEtlErrorLogService {

    private static Logger logger = LoggerFactory.getLogger(EtlErrorLogServiceImpl.class);

    private static final String logger_prefix = "wolf-etl#com.wolf.etl.service.impl#EtlErrorLogServiceImpl";

    @Override
    public boolean insert(EtlErrorLogModel model) {
        return super.insertModel(model);
    }

    @Override
    public PageResult findByPage(EtlErrorLogModel model, PageBean pageBean) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select * from etl_error_log t where 1=1 ");

        List<ParamBean> paramBeans = new ArrayList<ParamBean>();
        if (StringUtils.isNotEmpty(model.getError_code())) {
            ParamBean paramBean = new ParamBean();
            paramBean.setWhereField("t.code");
            paramBean.setField("code");
            paramBean.setValue(model.getError_code());
            paramBean.setType(QUERY_TYPE.EQUAL.getType());
            paramBeans.add(paramBean);
        }

        if (NumberUtil.isNotEmpty(model.getClient_id())) {
            ParamBean paramBean = new ParamBean();
            paramBean.setWhereField("t.client_id");
            paramBean.setField("client_id");
            paramBean.setValue(model.getClient_id());
            paramBean.setType(QUERY_TYPE.EQUAL.getType());
            paramBeans.add(paramBean);
        }


        PageInfo<EtlErrorLogModel> vos = findByPageInfo(sql.toString(), paramBeans, model, pageBean);

        PageResult result = new PageResult();
        result.buildResult(vos);
        return result;
    }

}
